package com.tanhua.server.controller;

import com.tanhua.common.vo.ErrorResult;
import com.tanhua.server.service.BaiduService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author 王加鑫
 * @Date 2021/09/14 21:18
 * @Since JDK 1.8
 * 地理相关Controller
 */
@RestController
@RequestMapping("baidu")
public class BaiduController {

    @Autowired
    private BaiduService baiduService;

    /**
     * 上传地理位置
     * @param param
     * @return
     */
    @RequestMapping("location")
    public ResponseEntity<ErrorResult> updateLocation(@RequestBody Map<String, Object> param){
        Double latitude = Double.valueOf(param.get("latitude").toString());
        Double longitude = Double.valueOf(param.get("longitude").toString());
        String addrStr = param.get("addrStr").toString();
        try {
            Boolean result = this.baiduService.updateLocation(latitude,longitude,addrStr);
            if(result){
                return ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        ErrorResult errorResult = ErrorResult.builder().errCode("000001").errMessage("上传地理位置信息失败").build();
        return ResponseEntity.status(500).body(errorResult);
    }
}
